package com.ebraga.trackerclub.android.manager.core;

import java.util.List;

import com.ebraga.trackerclub.android.dao.api.ChronometerDao;
import com.ebraga.trackerclub.android.dao.api.ParameterDao;
import com.ebraga.trackerclub.android.dao.entity.ChronometerAndroid;
import com.ebraga.trackerclub.android.exception.BackofficeDBConnectionException;
import com.ebraga.trackerclub.android.exception.dao.BackofficeDaoException;
import com.ebraga.trackerclub.android.exception.manager.BackofficeIllegalArgumentManagerException;
import com.ebraga.trackerclub.android.exception.manager.BackofficeManagerException;
import com.ebraga.trackerclub.android.manager.api.ChronometerManager;
import com.ebraga.trackerclub.android.util.DLog;

public abstract class ChronometerManagerImpl implements ChronometerManager {
	
	protected ParameterDao  parameterDao;
	protected ChronometerDao   chronometerDao;
	
	protected void setParameterDao (ParameterDao  parameterDao){
		this.parameterDao = parameterDao;
	}
	
	protected void setChronometerDao (ChronometerDao   chronometerDao){
		this.chronometerDao = chronometerDao;
	}		

	public void sendChronometerData(ChronometerAndroid chronometerAndroid)
			throws BackofficeIllegalArgumentManagerException,
			BackofficeDBConnectionException,
			BackofficeManagerException {

		if (chronometerAndroid == null){
			throw new BackofficeIllegalArgumentManagerException("Cronometro invalida");
		}
	
		try {
			chronometerDao.insert(chronometerAndroid);
		}catch(BackofficeDBConnectionException db){
			DLog.e(db);
			throw new BackofficeDBConnectionException ("Erro ao conectar banco de dados");
		} catch (BackofficeDaoException e) {
			DLog.e(e);
			throw new BackofficeManagerException(e.getMessage());
		}
	
	}
	

	public List<ChronometerAndroid> list() throws BackofficeIllegalArgumentManagerException,
			BackofficeDBConnectionException,
			BackofficeManagerException {
		
		List<ChronometerAndroid> chronometerLst = null;
		try {
			chronometerLst = chronometerDao.list();
			return chronometerLst;
		}catch(BackofficeDBConnectionException db){
			DLog.e(db);
			throw new  BackofficeDBConnectionException ("Erro ao conectar banco de dados");
		} catch (BackofficeDaoException e) {
			DLog.e(e);
			throw new BackofficeManagerException("Erro ao recuperar ultima posição do usuario");
		}
		
	}	

}
